home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Inside Mac Games Volume 5 #3
/
IMG 46 Vol 5-3.iso
/
More Goodies
/
More For Your Game
/
Realmz
/
Character Master Source
/
Character Master
/
my files.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-16
|
12KB
|
506 lines
#include "my files.h"
#include "main.h"
#include "character class.h"
#include "my dialogs.h"
#include "MoreFilesExtras.h"
extern nemesisGlobalPtr G;
Boolean IsFileRealmz( FSSpec & theSpec )
{
OSErr error = noErr;
FInfo theFInfo;
error = FSpGetFInfo( &theSpec, &theFInfo );
if( error )
return false;
if( theFInfo.fdType != kApplicationType )
error = true;
if( theFInfo.fdCreator != kRealmzCreator )
error = true;
if( error )
return false;
else
return true;
}
Boolean IsOpenableFile( FSSpec & theSpec )
{
OSErr error = noErr;
Boolean rightType = false;
FInfo theFInfo;
error = FSpGetFInfo( &theSpec, &theFInfo );
if( error )
return false;
switch( theFInfo.fdType )
{
case kFighterType:
case kMonkType:
case kPaladinType:
case kRangerType:
case kThiefType:
case kMagicType:
case kClericType:
case kEnchanterType: rightType = true;
break;
default: rightType = false;
break;
}
if( error || (!rightType) )
return false;
else
return true;
}
Boolean CheckAlreadyOpen( const FSSpec &theFile )
{
Boolean open = false;
DialogRef theDialog = G->DialogList();
baseModelessDialogPtr myDialog;
while( theDialog && !open )
{
myDialog = NemesisGetBaseMlessPtr( theDialog );
open = NemesisSameFileSpec( theFile, ((character *)(myDialog->DialogData()))->TheFileSpec() );
if (open)
{
SelectWindow( (WindowRef)theDialog );
}
theDialog = myDialog->NextDialog();
}
return(open);
}
OSErr DoOpen( FSSpec theSpec )
{
DialogRef theDialog = nil;
OSErr error = noErr;
int count;
if( !CheckAlreadyOpen( theSpec ) ) // Check its not already open
{
// if its good, get on with setting up the dialog.
error = NemesisGetDialog( kEditCharacterDialogID, nil, kInFront, theDialog );
if( error ) return error;
for( count = 0; count < kNumOutlines; count++ )
NemesisSetupOutline( theDialog, kECOutline[count] );
// Stuff a pointer to the editCharacterDialog in the dialog
SetWRefCon( (WindowRef)theDialog,
(long)(new editCharacterDialog(theDialog, nil)) );
// Now setup the dialog with the character data
// and tell the character which dialog it belongs to.
(NemesisGetBaseMlessPtr( theDialog ))->SetDialogData( ((long)(new character(theSpec, theDialog))) );
// Right. Now tell the character to open itself.
error = ((character *)(NemesisGetBaseMlessPtr( theDialog ))->DialogData())->OpenCharacter();
if( error ) return error;
// Okay-dokey, now set up the dialog with the data contained in the character
((character *)(NemesisGetBaseMlessPtr( theDialog ))->DialogData())->SetupENDialogControls();
// Finally, set the dialog kind and show it.
NemesisSetDialogKind( theDialog, kCharacterDKind );
NemesisShowDialog( theDialog );
NemesisAddDialogToList( theDialog );
}
return error;
}
OSErr DoOpen()
{
StandardFileReply theReply;
OSErr error = noErr;
Point tempPoint;
if( !CMData()->KnowWhereRealmzIs() )
DoLocateRealmz();
if( !CMData()->KnowWhereRealmzIs() )
return error;
SetPt( &tempPoint, -1, -1 );
CustomGetFile( CMData()->RealmzCharFileFilter(),
kNumberOfTypes,
theTypeList,
&theReply,
kGetCharDialogID,
tempPoint,
CMData()->RealmzCharDialogHook(),
CMData()->GetFileModalFilter(),
nil,
nil,
&theReply );
if( theReply.sfGood )
error = DoOpen( theReply.sfFile );
return error;
}
void DoLocateRealmz()
{
StandardFileReply theReply;
OSErr error = noErr;
Point tempPoint;
SetPt( &tempPoint, -1, -1 );
CustomGetFile( CMData()->RealmzAppFileFilter(),
1,
realmzAppType,
&theReply,
kGetAppDialogID,
tempPoint,
CMData()->RealmzAppDialogHook(),
CMData()->GetFileModalFilter(),
nil,
nil,
nil );
if( theReply.sfGood )
{
CMData()->SetRealmzLocation( theReply.sfFile );
CMData()->SetKnowWhereRealmzIs( true );
DoReadRealmzData();
}
else
CMData()->SetKnowWhereRealmzIs( false );
}
void DoReadRealmzData()
{
int refNum = 0;
short tempHit;
int count1, count2;
OSErr error = noErr;
Str255 tempStr;
Str255 tempDesc;
Str255 whatImDoing = "\p";
DialogRef theDialog;
SetCursor( &G->WatchCursor() );
error = NemesisGetDialog( kLoadingDataID, nil, kInFront, theDialog );
if( error )
{
SysBeep( 30 );
theDialog = nil;
}
if( theDialog )
{
SelectWindow( theDialog );
ShowWindow( theDialog );
DrawDialog( theDialog );
NemesisGetIndString( kDoingStringID, kOpeningRealmz, whatImDoing );
NemesisSetItemText( theDialog, kLoadingDataText, whatImDoing );
}
refNum = FSpOpenResFile( &(CMData()->RealmzLocation()), fsRdPerm );
if( refNum < 0 )
{
if( theDialog )
{
NemesisGetIndString( kDoingStringID, kClosingRealmzError, whatImDoing );
NemesisSetItemText( theDialog, kLoadingDataText, whatImDoing );
}
CloseResFile( refNum ); // Shouldn't be necessary but just in case
UseResFile( G->DefaultResFile() ); // Just in case
if( theDialog )
DisposeDialog( theDialog );
SetCursor( &G->ArrowCursor() );
CMData()->SetKnowWhereRealmzIs( false );
NemesisShowError( kResFromRealmzError );
return;
}
UseResFile( refNum );
if( theDialog )
{
NemesisGetIndString( kDoingStringID, kReadingSpellNames, whatImDoing );
NemesisSetItemText( theDialog, kLoadingDataText, whatImDoing );
}
for( count1 = 0; count1 < 7; count1++ )
{
for( count2 = 0; count2 < 12; count2++ )
{
NemesisPStrCpy( tempStr, "\p«Unknown»" ); // Just in case this fails
GetIndString( tempStr, kMagicUserSpells[count1], (count2+1) );
CMData()->SetSpellName( kMagicSpellList, count1, count2, tempStr );
}
}
for( count1 = 0; count1 < 7; count1++ )
{
for( count2 = 0; count2 < 12; count2++ )
{
NemesisPStrCpy( tempStr, "\p«Unknown»" ); // Just in case this fails
GetIndString( tempStr, kClericSpells[count1], (count2+1) );
CMData()->SetSpellName( kClericSpellList, count1, count2, tempStr );
}
}
for( count1 = 0; count1 < 7; count1++ )
{
for( count2 = 0; count2 < 12; count2++ )
{
NemesisPStrCpy( tempStr, "\p«Unknown»" ); // Just in case this fails
GetIndString( tempStr, kEnchanterSpells[count1], (count2+1) );
CMData()->SetSpellName( kEnchanterSpellList, count1, count2, tempStr );
}
}
if( theDialog )
{
NemesisGetIndString( kDoingStringID, kReadingSpellDescriptions, whatImDoing );
NemesisSetItemText( theDialog, kLoadingDataText, whatImDoing );
}
for( count1 = 0; count1 < 7; count1++ )
{
for( count2 = 0; count2 < 12; count2++ )
{
NemesisPStrCpy( tempDesc, "\p«Unknown»" ); // Just in case this fails
GetIndString( tempDesc, (kMagicUserSpells[count1] * -1), (count2+1) );
CMData()->SetSpellDescription( kMagicSpellList, count1, count2, tempDesc );
}
}
for( count1 = 0; count1 < 7; count1++ )
{
for( count2 = 0; count2 < 12; count2++ )
{
NemesisPStrCpy( tempDesc, "\p«Unknown»" ); // Just in case this fails
GetIndString( tempDesc, (kClericSpells[count1] * -1), (count2+1) );
CMData()->SetSpellDescription( kClericSpellList, count1, count2, tempDesc );
}
}
for( count1 = 0; count1 < 7; count1++ )
{
for( count2 = 0; count2 < 12; count2++ )
{
NemesisPStrCpy( tempDesc, "\p«Unknown»" ); // Just in case this fails
GetIndString( tempDesc, (kEnchanterSpells[count1] * -1), (count2+1) );
CMData()->SetSpellDescription( kEnchanterSpellList, count1, count2, tempDesc );
}
}
if( theDialog )
{
NemesisGetIndString( kDoingStringID, kClosingRealmz, whatImDoing );
NemesisSetItemText( theDialog, kLoadingDataText, whatImDoing );
}
CloseResFile( refNum );
UseResFile( G->DefaultResFile() );
if( theDialog )
{
NemesisGetIndString( kDoingStringID, kSettingUpDirectories, whatImDoing );
NemesisSetItemText( theDialog, kLoadingDataText, whatImDoing );
}
// Setup char ƒ
NemesisGetIndString( kFilenamesID, kCharacterF, whatImDoing );
OSErr newError = noErr;
FSSpec tempSpec;
long tempDirID;
Boolean isDir;
tempSpec = CMData()->RealmzLocation();
NemesisPStrCpy( tempSpec.name, whatImDoing );
newError = FSpGetDirectoryID( &tempSpec, &tempDirID, &isDir );
if( isDir && (!newError) )
{
tempSpec.parID = tempDirID;
tempSpec.name[0] = 0;
}
CMData()->SetCharFLocation( tempSpec );
// Setup DataCD location
if( isDir && (!newError) )
{
NemesisGetIndString( kFilenamesID, kDataCD, whatImDoing );
NemesisPStrCpy( tempSpec.name, whatImDoing );
CMData()->SetIsDataCD( true );
}
else
CMData()->SetIsDataCD( false );
CMData()->SetCharDataCDLocation( tempSpec );
// Setup save ƒ location
NemesisGetIndString( kFilenamesID, kSaveF, whatImDoing );
tempSpec = CMData()->RealmzLocation();
NemesisPStrCpy( tempSpec.name, whatImDoing );
newError = FSpGetDirectoryID( &tempSpec, &tempDirID, &isDir );
if( isDir && (!newError) )
{
tempSpec.parID = tempDirID;
tempSpec.name[0] = 0;
}
CMData()->SetSaveFLocation( tempSpec );
if( theDialog )
DisposeDialog( theDialog );
SetCursor( &G->ArrowCursor() );
}
pascal Boolean MyRealmzAppFileFilter( CInfoPBPtr pb, void * myData )
{
Boolean dontShowFile = true;
if( pb->hFileInfo.ioFlFndrInfo.fdCreator == kRealmzCreator )
dontShowFile = false;
else
dontShowFile = true;
return dontShowFile;
}
pascal Boolean MyRealmzCharFileFilter( CInfoPBPtr pb, void * myData )
{
Boolean dontShowFile = true;
if( CMData()->ShowAll() )
{
if( pb->hFileInfo.ioFlFndrInfo.fdCreator == kRealmzCreator )
dontShowFile = false;
else
dontShowFile = true;
}
else
{
if( (pb->hFileInfo.ioFlFndrInfo.fdType == CMData()->TypeToShow() ) &&
(pb->hFileInfo.ioFlFndrInfo.fdCreator == kRealmzCreator) )
dontShowFile = false;
else
dontShowFile = true;
}
return dontShowFile;
}
pascal int MyRealmzCharDialogHook( int itemHit, DialogRef theDialog, void * myData )
{
int itemHitToReturn = itemHit;
int temp = 0;
switch( itemHit )
{
// Check for first call
case sfHookFirstCall : NemesisSetControlValue( theDialog, kClassPopup, CMData()->CurrentType() );
itemHitToReturn = sfHookNullEvent;
if( CMData()->FirstTimeOpenedCharacter() )
{
CMData()->SetFirstTimeOpenedCharacter( false );
((StandardFileReply*)(myData))->sfFile.parID = CMData()->CharFLocation().parID;
((StandardFileReply*)(myData))->sfFile.vRefNum = CMData()->CharFLocation().vRefNum;
itemHitToReturn = sfHookChangeSelection;
}
break;
case sfItemOpenButton :
case sfItemCancelButton :
case sfItemVolumeUser :
case sfItemEjectButton :
case sfItemDesktopButton : NemesisPlayGoodClick();
break;
case kClassPopup : temp = NemesisGetControlValue( theDialog, kClassPopup );
if( temp != CMData()->CurrentType() )
{
CMData()->SetCurrentType( temp );
itemHitToReturn = sfHookRebuildList;
}
break;
default : itemHitToReturn = itemHit;
break;
}
return itemHitToReturn;
}
pascal int MyRealmzAppDialogHook( int itemHit, DialogRef theDialog, void * myData )
{
int itemHitToReturn = itemHit;
int temp = 0;
switch( itemHit )
{
case sfItemOpenButton :
case sfItemCancelButton :
case sfItemVolumeUser :
case sfItemEjectButton :
case sfItemDesktopButton : NemesisPlayGoodClick();
break;
default : itemHitToReturn = itemHit;
break;
}
return itemHitToReturn;
}
pascal Boolean MyGetFileModalFilter( DialogRef theDialog, EventRecord * theEvent, int * itemHit, void * myData )
{
Boolean haveHandled = false;
Rect dragRect;
WindowRef hitWindow = nil;
short windowPart = FindWindow(theEvent->where, &hitWindow);
switch( theEvent->what )
{
case updateEvt :
if( ((DialogRef)theEvent->message) != ((DialogRef)FrontWindow()) )
{
baseDialogPtr myDialog = NemesisGetBaseDPtr( (DialogRef)theEvent->message );
if( myDialog )
{
myDialog->DoUpdate( nil );
haveHandled = true;
}
}
break;
case mouseDown:
if ( theEvent->modifiers & cmdKey )
{
if (windowPart == inDrag)
{
dragRect = (**GetGrayRgn()).rgnBBox;
DragWindow( hitWindow, theEvent->where, &dragRect );
haveHandled = true;
}
}
else
{
if( windowPart == inDrag && (hitWindow == theDialog))
{
dragRect = (**GetGrayRgn()).rgnBBox;
DragWindow( hitWindow, theEvent->where, &dragRect );
haveHandled = true;
}
}
}
return haveHandled;
}